package cn.wolfcode.cotroller;

import cn.wolfcode.domain.Dept;
import cn.wolfcode.domain.Result;
import cn.wolfcode.service.DeptService;
import lombok.extern.slf4j.Slf4j;

import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/depts")
public class DeptCotroller {
    @Autowired
    private DeptService deptService;

    @GetMapping
    public Result list(){
        log.info("查询所有部门信息");
        List<Dept> list = deptService.list();
        return Result.success(list);
    }

     @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id){
        log.info("删除部门信息");
        deptService.delete(id);
        return Result.success();
    }
  @PostMapping
    public Result save(@RequestBody Dept dept){
        log.info("保存部门信息");
        deptService.save(dept);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result selById(@PathVariable Long id){
        log.info("查询部门信息");
        Dept dept = deptService.selById(id);
        return Result.success(dept);
    }
    @PutMapping
    public Result update(@RequestBody Dept dept){
        log.info("更新部门信息");
        deptService.update(dept);
        return Result.success();
    }

}
